#include <stdio.h>

int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};

int* binary_search(int* a, int Len, int k)
{
	int low = 0;
	int high = Len - 1;
	int mid = 0;

	while(low <= high)
	{
		mid = (low + high) / 2;
		if (a[mid] == k)
			return &a[mid];
		else if (a[mid] < k)
			low = mid + 1;
		else
			high = mid - 1;
	}
	return NULL;
}


int main(void)
{
	int* p = binary_search(a, 9, 0);
	if (p == NULL)
		printf("查找失败\n");
	else
		printf("查找成功，处在位置%d.\n", (p - &a[0]));
}
